package com.daocao.hua.api.requestInfo;

import com.daocao.hua.api.Api;
import com.daocao.hua.api.bean.LoginBean;
import com.daocao.hua.api.bean.RepayStatusDialogBean;
import com.daocao.hua.api.bean.ShenheBean;
import com.daocao.hua.api.callback.LoginContract;
import com.daocao.hua.api.callback.ShenheContract;
import com.daocao.hua.util.Network;
import com.daocao.hua.util.RxLifeUtil;
import com.daocao.hua.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class ShenheRequest extends BaseRequest<ShenheContract.View> implements ShenheContract.Presenter<ShenheContract.View> {

    public static ShenheRequest create() {
        return new ShenheRequest();
    }

    public String SUCCESS = "success";
    public String FAILED = "failed";


    @Override
    public void getRestartPay(String order) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        ShenheBean bean = new ShenheBean();
        bean.notice_sn = order;
        mView.onRequestStart();
        Api.api_service.getRestartPay(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getRestartPaySuccess(result);
                });
    }

    @Override
    public void confirmDialog(String notice_id, String confirm) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        RepayStatusDialogBean bean = new RepayStatusDialogBean();
        bean.notice_id = notice_id;
        bean.confirm = confirm;
        Api.api_service.getConfirmDilaog(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.confirmDialogSuccess(result, confirm);
                });
    }

    @Override
    public void getRepayDialog() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();

        Api.api_service.getRepayDialog().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getRepayDialogSuccess(result);
                });
    }
}
